package day17;

public class RunnableTicketPractice {
    public static void main(String[] args) {
        ticketPrc tPrc = new ticketPrc();
        Thread t1 = new Thread(tPrc,"阿龙");
        Thread t2 = new Thread(tPrc,"阿飞");
        Thread t3 = new Thread(tPrc,"阿勇");
        Thread t4 = new Thread(tPrc,"阿彪");
        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
class ticketPrc implements Runnable{
    int tickets=100;
    Object oo=new Object();
    public void run() {
        while (true){
            synchronized (oo){
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (tickets>0)
                    System.out.println(Thread.currentThread().getName()+","+tickets--);
                if (tickets<=0)break;
            }

        }
    }
}